<template>

	<div>


		<el-row :gutter="10">
			<el-col :span="5">
				<el-input v-model="search.username" placeholder="客户姓名"></el-input>
			</el-col>
			<el-col :span="19" >
				<el-button type="primary" icon="el-icon-search" plain @click="searchData()" >查询</el-button>
				<el-button type="primary" icon="el-icon-circle-plus-outline" plain @click="add()">登记</el-button>
			</el-col>
		</el-row>
		
		
		<el-table :data="result.tableData" style="width: 100%" @selection-change="handleSelectionChange">
			
			<el-table-column label="序号" prop="id">

			</el-table-column>

			<el-table-column label="客户姓名" prop="username">
			</el-table-column>

			<el-table-column label="性别" prop="gender">
			</el-table-column>

			<el-table-column label="年龄" prop="age">
			</el-table-column>

			<el-table-column label="身份证号" prop="idNum">
			</el-table-column>

			<el-table-column label="房间号" prop="roomNum">
			</el-table-column>

			<el-table-column label="所属楼房" prop="building">
			</el-table-column>

			<el-table-column label="档案号" prop="fileNumber">
			</el-table-column>
			
			<el-table-column label="老人类型" prop="patientType">
				<template slot-scope="scope">
				
					<el-tag v-if="scope.row.patientType == '活力老人'">活力老人</el-tag>
				
					<el-tag v-if="scope.row.patientType == '自理老人'">自理老人</el-tag>
					
					<el-tag v-if="scope.row.patientType == '护理老人'">护理老人</el-tag>
				</template>
			</el-table-column>

			<el-table-column label="入住时间" prop="checkInTime">
			</el-table-column>

			<el-table-column label="合同到期时间" prop="expirationTime">
			</el-table-column>

			<el-table-column label="联系电话" prop="telephone">
			</el-table-column>

			<el-table-column label="家属" prop="family">
			</el-table-column>

			<el-table-column label="陪住人" prop="companyPerson">
			</el-table-column>

			<el-table-column label="评估医生" prop="evaluationDoctor">
			</el-table-column>

			<el-table-column label="负责医生" prop="chargeDoctor">
			</el-table-column>

			<el-table-column label="护工" prop="nurse">
			</el-table-column>

			<el-table-column label="健康管家" prop="healthButler">
			</el-table-column>
			
			<el-table-column label="备注" prop="notes">
			</el-table-column>

			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button size="mini" @click="edit(scope.row.id)">编辑</el-button><br /><br />
					<el-button size="mini" type="danger" @click="del(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>


		</el-table>
		
		
		<el-dialog title="入住登记" :visible.sync="show" :close-on-click-modal="false" width="500px">
			<CheckInEdit v-if="show" :show.sync="show" @getData="getData()" :editid="editid" :key="showNum">
			</CheckInEdit>
		</el-dialog>
		
		
		


		<el-pagination
      style="margin-top:20px;"
      background
      layout="prev, pager, next"
      :page-count="result.pages"
      :current-page.sync="query.pageNo"
      :page-size="query.pageSize"
      @current-change="getData()">
    </el-pagination>
  

	</div>
</template>

<script>
	import CheckInEdit from '@/views/check_in/edit'
	export default {
		name: 'CheckIn',
		components: {
			CheckInEdit
		},
		data() {
			return {
				showNum: 0,
				editid: null,
				search: {
					username: ''
				},
				query: {
					username: '',
					pageNo: 1,
					pageSize: 8
				},
				result: {
					tableData: [],
					pages: 0
				},
				show: false,
				selectedrow: [],
				title: ''
			}
		},
		created() {
			this.getData()
		},
		methods: {
			getData() {
				this.axios.get('/checkIn/list', response => {
					this.result.tableData = response.obj.records
					this.result.pages = response.obj.pages
					
					console.log(this.result.tableData)
				}, this.query)
			},
			searchData() {
				this.query.username = this.search.username;
				this.query.pageNo = 1;
				this.getData();
			},
			edit(id) {
				this.editid = id;
				this.showNum++;
				this.show = true;
			},
			add() {
				this.showNum++;
				this.editid = null;
				this.show = true;
			},

			del(id) {
				this.axios.del('/checkIn/del', response => {
					this.getData()
				}, {
					id: id
				})
			},
			handleSelectionChange(val) {
				// val参数为所有选中行的数据
				this.selectedrow = val
			},
			batchdel() {
				if (this.selectedrow.length === 0) {
					this.$message('没有任何被选中的数据');
				} else {
					const ids = []
					for (let i = 0; i < this.selectedrow.length; i++) {
						ids.push(this.selectedrow[i].id)
					}
					this.axios.del('/ums-user/batchdel', response => {
						this.getData()
					}, {
						ids: ids
					})
				}
			},
			handleBack(id) {
				this.axios.del('/ums-user/back', response => {
					this.getData()
				}, {
					id: id
				}, 'back')
			},
			gorole(id) {
				this.$router.push({
					path: '/user-role',
					query: {
						id: id
					}
				})
			}
		}
	}
</script>
<style scoped>
	/* el-table el-table-column{
		text-align: center;
	} */
</style>

